package com.xinqi.modules.homework.homework.assistant;

import com.xinqi.common.base.response.R;
import com.xinqi.common.core.enums.AssistantMessageTypeEnum;
import com.xinqi.modules.chat.chat.official.client.ChatAssistantContentClient;
import com.xinqi.modules.chat.chat.official.dto.req.ChatAssistantContentCreateDTO;
import com.xinqi.modules.course.clazz.client.ClassClient;
import com.xinqi.modules.course.clazz.dto.rsp.ClassResultDTO;
import com.xinqi.modules.course.clazz.dto.rsp.ClassStudentResultDTO;
import com.xinqi.modules.homework.homework.assistant.service.AssistantHomeworkService;
import com.xinqi.modules.homework.homework.domain.CourseHomeworkStudentLogEntity;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 新奇助手发送消息公共Service
 */
@Service("assistantListen")
@RequiredArgsConstructor
public class AssistantListen {
    private final ClassClient classClient;

    private final AssistantHomeworkService assistantHomeworkService;

    private final ChatAssistantContentClient chatAssistantContentClient;

    /**
     * 新奇助手公共发布方法
     * 课程内容ID contentId
     * 作业轮数 times
     */
    public void releaseCourseContent(Long contentId, AssistantMessageTypeEnum type) {
        chatAssistantContentClient.batchInsert(assistantHomeworkService.releaseHomework(contentId));
    }

    /**
     * 作业催交、打回、成绩
     */
    public void operaHomeworkStudent(Long contentId, Integer times, List<CourseHomeworkStudentLogEntity> students, Integer opType, String repulseReason) {
        List<ChatAssistantContentCreateDTO> list = assistantHomeworkService.operaStudentHomework(contentId, times, students, opType, repulseReason);
        if (Objects.nonNull(list)) {
            chatAssistantContentClient.batchInsert(list);
        }
    }

    /**
     * 提交作业发送系统通知
     */
    public void submitSysChat(Long classId, Long contentId, Long studentId, Integer times) {
        assistantHomeworkService.submitSysChat(classId, contentId, studentId, times);
    }

}
